USER_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'group_by': '_chn.keyword',
    'interval_type_list': ['day'],
    'target_event_id': ['cp_game', 'cp_lottery', 'recharge', 'withdraw', "platform_reward", "active", "register"],
    'values': [
        {
            "value_id": "active_device",
            "target_value": "_aid.keyword",
            "value_name": "登录设备",
            "filter": [
                {'term': {'_event_id': 'active'}},
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "登录账号",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "not_filter": [
                {'term': {'_user_id': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "real_active_user",
            "target_value": "_user_id",
            "value_name": "活跃账号",
            "filter": [
                {'terms': {'_event_id': ['withdraw', 'recharge', 'cp_game', 'cp_lottery', 'active', 'register']}}
            ],
            "value_type": "long",
            "operation": "cardinality"
        },
        {
            "value_id": "bet_user",
            "target_value": "_user_id",
            "value_name": "投注帐号",
            "filter": [
                {'terms': {'_event_id': ['cp_game', 'cp_lottery']}}
            ],
            "value_type": "long",
            "operation": "cardinality"
        },
        {
            "value_id": "active_rate",
            "value_name": "投注率",
            "value_expr": "bet_user/active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'terms': {'_event_id': ['recharge']}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "recharge_rate",
            "value_name": "付费率",
            "value_expr": "recharge_user/real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_price",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'terms': {'_event_id': ['recharge']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "recharge_user_arpu",
            "value_name": "ARPPU",
            "value_expr": "recharge_price/recharge_user",
            "adjust_amount": True
        },
        {
            "value_id": "real_active_user_arpu",
            "value_name": "ARPU",
            "value_expr": "recharge_price/real_active_user",
            "adjust_amount": True
        },
        {
            "value_id": "withdraw_user",
            "target_value": "_user_id",
            "value_name": "提现账号",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "withdraw_price",
            "target_value": "withdraw_price",
            "value_name": "提现金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}},
                {'term': {'withdraw_status': 2}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "profit_amount",
            "value_name": "财务营收",
            "value_expr": "withdraw_price - recharge_price",
            "adjust_amount": True
        },
        {
            "value_id": "profit_amount_rate",
            "value_name": "利润率",
            "value_expr": "profit_amount / recharge_price",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "bet_amount",
            "target_value": ["cp_game_price", "+", "cp_lottery_price"],
            "value_name": "投注金额",
            "filter": [
                {'terms': {'_event_id': ['cp_game', 'cp_lottery']}}
            ],
            "not_filter": [
                {'range': {'cp_lottery_refund': {'gt': 0}}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "bet_profit_amount",
            "target_value": ["cp_game_price", "+", "cp_lottery_price", "-", "cp_lottery_win", "-",
                             "cp_lottery_bonus", '-', "cp_game_win", '-', "cp_lottery_refund"],
            "value_name": "玩法营收",
            "filter": [
                {'terms': {'_event_id': ['cp_game', 'cp_lottery']}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "profit_rate",
            "value_name": "抽水率",
            "value_expr": "bet_profit_amount / bet_amount",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "platform_reward",
            "target_value": "platform_reward_reward_amount",
            "value_name": "系统奖励",
            "filter": [
                {'term': {'_event_id': 'platform_reward'}}
            ],
            "value_type": "float",
            "adjust_amount": True
        }
    ]
}
